import { Column, Entity, PrimaryColumn, PrimaryGeneratedColumn } from "typeorm";

export enum ProxyBrowserType {
    UNKNOWN = 0,
    WEIBO = 1,
    JD = 2,
}
@Entity({
    name: 'proxy_browser'
})
export class ProxyBrowser {
    @PrimaryColumn({ default: '' })
    uuid: string;

    @Column({ default: '', comment: '所在客户端id' })
    client_id: string;

    @Column({ default: ProxyBrowserType.UNKNOWN, type: 'smallint' })
    type: ProxyBrowserType
}

@Entity({
    name: 'proxy_browser_page'
})
export class ProxyBrowserPage {
    @PrimaryColumn({ default: '' })
    uuid: string;

    @Column({ default: '' })
    browser_id: string;

    @Column({ default: '' })
    client_id: string;
}

@Entity({
    name: 'proxy_page_event'
})
export class ProxyPageEvent {
    @PrimaryColumn()
    uuid: string;

    @Column()
    browser_id: string;

    @Column()
    page_id: string;

    @Column()
    client_id: string;

    @Column()
    type: string;

    @Column({ type: 'jsonb' })
    value: any;
}

@Entity({
    name: `proxy_resource`
})
export class ProxyResource {
    @PrimaryColumn()
    uuid: string;

    @Column()
    url: string;

    @Column()
    type: string;
}

export type CookieSourceScheme = 'Unset' | 'NonSecure' | 'Secure';
export type CookieSameSite = 'Strict' | 'Lax' | 'None';
export type CookiePriority = 'Low' | 'Medium' | 'High';
export enum ProxyUserStatus {
    UNKNOWN = 0,
    ONLINE = 1,
    OFFLINE = 2,
}
export enum ProxyUserType {
    UNKNOWN = 0,
    WEIBO = 1,
    JD = 2,
}
/**
 * 已登陆用户
 */
@Entity({
    name: 'proxy_user'
})
export class ProxyUser {
    @PrimaryColumn()
    uuid: string;

    @Column()
    uid: string;

    @Column()
    avatar: string;

    @Column({ type: 'jsonb', nullable: true })
    info: any;

    @Column({ default: ProxyUserType.UNKNOWN, type: 'smallint' })
    type: ProxyUserType;

    @Column({ default: ProxyUserStatus.UNKNOWN, type: 'smallint' })
    status: ProxyUserStatus;

    @Column({ default: '' })
    login_at: string;
}

@Entity({
    name: 'proxy_cookies'
})
export class ProxyCookies {
    @PrimaryGeneratedColumn()
    id: number;

    @Column({ type: 'uuid' })
    user_id: string;

    @Column({ default: '' })
    name: string;

    @Column({ default: '' })
    value: string;

    @Column({ default: '' })
    domain: string;

    @Column()
    path: string;

    @Column({ type: 'timestamp' })
    expires: Date;

    @Column({ default: 0 })
    size: number;

    @Column({ default: false })
    httpOnly: boolean;

    @Column({ default: false })
    secure: boolean;

    @Column({ default: false })
    session: boolean;

    @Column({ default: 'None' })
    sameSite: CookieSameSite;

    @Column({ default: 'Low' })
    priority: CookiePriority;

    @Column({ default: false })
    sameParty: boolean;

    @Column({ default: 'Unset' })
    sourceScheme: CookieSourceScheme;

    @Column({ default: '' })
    partitionKey: string;

    @Column({ default: false })
    partitionKeyOpaque: boolean;
}